package kks;

import static org.junit.Assert.assertEquals;
import kks.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Verifies that the CounterAll moves in a horizontal or vertical direction (not diagonally).
 * 
 * @author Kelli Sawai
 * 
 */
public class TestMovementDirection extends RobotTestBed {

  // Heading of robot
  double heading;
  // Keeps track if the heading is in the right direction
  boolean correctHeading = false;

  /**
   * Specifies that SpinBot and CounterAll are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SpinBot,kks.CounterAll";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if Counter all is vertical or horizontal.
   * 
   * @param event information stored about the robots at the end of a turn
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // IRobotSnapshot robot creation taken from David Mau
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    heading = Math.toDegrees(robot.getBodyHeading());

    if (heading == 0 || heading == 90 || heading == 180 || heading == 270) {
      correctHeading = true;
    }

  }

  /**
   * The actual test, which asserts that CounterAll is moving in a horizontal or vertical direction.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertEquals("Check CounterAll moving in level direction.", correctHeading, true);
  }
}
